﻿using GBH.Models;
using GBH.Models.Dto;
using GBHNawaData;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace GBH.Controllers
{
    public class MaterialApiController : ApiController
    {
        // GET api/materialapi
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET api/materialapi/5
        public HttpResponseMessage GetMatByMatNo(string matNo)
        {
            var matLocationProvider = new Models.Dao.MaterialLocationDao();
            var matWHProvider = new GBHNawaData.Dao.MaterialDao();
            var matProvider = new Models.Dao.MaterialDao();
            var matLocations = matLocationProvider.GetMatLocation(matNo.ToString());
            var matDetails = matWHProvider.GetMaterialByMatNo(matNo.ToString());
            var matDetailsExtension = matProvider.SelectMat(matNo);


            return this.Request.CreateResponse(HttpStatusCode.OK,
            new { MatLocations = matLocations, MatDetails = matDetails, MatDetailsExtentsion = matDetailsExtension });
        }
        
       

        public IList<vmsa140_product_basic> PostSearchMaterial(string matno, string namethai, string nameeng)
        {
            var matWHProvider = new GBHNawaData.Dao.MaterialDao();
            var matDetails = matWHProvider.SearchMaterial(matno, namethai, nameeng,"");
            return matDetails;
        }

        public IList<vmsa140_product_basic> PostSearchMaterialWithBarcode(string matno, string namethai, string nameeng, string barcode)
        {
            var matWHProvider = new GBHNawaData.Dao.MaterialDao();
            var matDetails = matWHProvider.SearchMaterial(matno, namethai, nameeng, barcode);
            return matDetails;
        }

        public bool PostSaveMat(MatDetailLocation matdetailsLocation)
        {
            var matprovider = new Models.Dao.MaterialDao();
            var matLicatoin = new Models.Dao.MaterialLocationDao();

            matprovider.SaveMat(matdetailsLocation.matDetail);
            matLicatoin.InsertMatLocation(matdetailsLocation.matLocation);
            return true;
        }

        public bool DeleteMat(int MatId)
        {
            var matLocationProvider = new Models.Dao.MaterialLocationDao();
            return matLocationProvider.DeleteMatLocation(MatId);
        }

        
    }
}
